package com.ssd.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ssd.entity.RegionEntity;
import com.ssd.mapper.RegionDao;
import com.ssd.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;

@Service
public class RegionServiceImpl extends ServiceImpl<RegionDao, RegionEntity> implements RegionService {

    @Autowired
    private RegionDao regionDao;

    /**
     * 分页查询商品列表，支持模糊查询
     *
     * @param pageNum  当前页码
     * @param pageSize 每页大小
     * @return 分页的商品集合
     */
    @Override
    public Page<Map<String, Object>> getRegionList(int pageNum, int pageSize,String regionName) {
        Page<Map<String, Object>> page = new Page<>(pageNum, pageSize);
        return regionDao.selectRegionList(page,regionName);
    }

    @Override
    public RegionEntity selectRegionById(Long regionId) {
        return regionDao.selectRegionById(regionId);
    }

    @Override
    public int insertRegion(RegionEntity region) {
        return regionDao.insert(region);
    }

    @Override
    public int updateRegion(RegionEntity region) {
        return regionDao.updateById(region);
    }

    @Override
    public int deleteRegionByRegionIds(Long[] regionIds) {
        return regionDao.deleteBatchIds(java.util.Arrays.asList(regionIds));
    }
}